//Stream流模块
const fs=require('fs');

//读取文件流
const rs=fs.createReadStream("06_sample.txt","utf-8");
rs.on("data",(chunk)=>{
    console.log(`DATA:${chunk}\n`);
});
rs.on("end",()=>{
    console.log("读取完成");
});
rs.on("error",(err)=>{
    console.error(err.message);
});

const ws1=fs.createWriteStream("06_output.txt","utf-8");
ws1.write("使用stream写入文本数据...\n");
ws1.write("写入结束");
ws1.end();

//文件流管道:拷贝
const reSrc=fs.createReadStream("06_sample.txt");
const wsDst=fs.createWriteStream("06_copied.txt");
reSrc.pipe(wsDst);